package net.xdclass.config;

import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.concurrent.ThreadPoolExecutor;

@EnableAsync
@Component
public class ThreadPoolTaskConfig {

	@Bean("threadPoolTaskExecutor")
    public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
		ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
		threadPoolTaskExecutor.setCorePoolSize(24);
		threadPoolTaskExecutor.setKeepAliveSeconds(30);
		threadPoolTaskExecutor.setMaxPoolSize(48);
		threadPoolTaskExecutor.setQueueCapacity(10000);
		threadPoolTaskExecutor.setThreadNamePrefix("小滴课堂Spring自带Asy前缀");
		threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
		threadPoolTaskExecutor.initialize();
		return threadPoolTaskExecutor;
	}
}
